package LeetCode;

import java.nio.file.StandardOpenOption;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}21:36
 */
public class LeetCode7 {
    public static void main(String[] args) {
//        System.out.println(new LeetCode7().reverse());
    }

    public int reverse(int x) {
        boolean small = false;
        if (x < 0){
            small = true;
            x = Math.abs(x);
        }
        String s = x+"";
        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()) {
            stack.push(c);
        }
        StringBuilder builder = new StringBuilder();
        while (stack.size() != 0){
            builder.append(stack.pop());
        }
        int results = 0;
        try {
           results = Integer.valueOf(builder.toString());
        }catch (Exception E){
            results = 0;
        }

        return small ? -results : results;
    }
}
